// pages/my/my.js
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
    openid:""
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
  },
  getUserProfile(e) {
    const that = this
    wx.getUserProfile({
      desc: '用于完善会员资料',
      success: (res) => {
        var x= res
        this.setData({
          hasUserInfo: true
        })
        wx.cloud.callFunction({
          name:"login",
          success:res=>{
              console.log("云函数调用成功")
              this.setData({
                openid:res.result.openid,
                userInfo:x.userInfo
              })
              that.data.userInfo.openid = that.data.openid
              console.log("userInfo",that.data.userInfo)
              wx.setStorageSync('userInfo', that.data.userInfo)
            },
          fail:res=>{
              console.log("云函数调用失败")
          }
        })
      }
    })
  },
  getUserInfo(e) {
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
})